package puzzle.puzzleup2008;



public class Queens {

	public static void main(String[] args) {
		
		int n = 4;
		int m = 1<<(n*n);
		int c = 0;
		for (int i = 0; i < m; i ++) {
			Integer[] a = transfer(i, n);
			if (check(a, n)) {
				c ++;
			}
		}
		System.out.println(c);
	}
	
	private static Integer[] transfer(int m, int n) {
		int size = n*n;
		Integer[] a = new Integer[size];
		int x = 0x1;
		int c = 0;
		do {
			a[c] = (x&m)>>c;
			c ++;
			x = x<<1;
		} while (c < size);
		return a;
	}
	
	private static boolean check(Integer[] c, int n) {
		
		Integer[] idx = null;
		for (int i = 0; i < n; i ++) {
			idx = fileIndexArray(n, i);
			if (empty(c, idx)) {
				return false;
			}
		}
		for (int i = 0; i < n; i ++) {
			idx = rankIndexArray(n, i);
			if (empty(c, idx)) {
				return false;
			}
		}
		return true;
	}
	
	private static Integer[] fileIndexArray(int n, int k) {
		
		Integer[] f = new Integer[n];
		for (int i = 0; i < n; i ++) {
			f[i] = n*k + i;
		}
		return f;
	}
	
	private static Integer[] rankIndexArray(int n, int k) {
		
		Integer[] r = new Integer[n];
		for (int i = 0; i < n; i ++) {
			r[i] = n*i + k;
		}
		return r;
	}
	
	private static boolean empty(Integer[] c, Integer... idx) {
		boolean t = true;
		for (int i = 0; i < idx.length; i ++) {
			t = t && (c[idx[i]]==0);
		}
		return t;
	}
}
